package com.lx.ngsl.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import com.lx.ngsl.core.user.service.UserService;

@Component
public class AppInterceptor implements HandlerInterceptor {

	@Autowired
	private UserService userService;
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		String uri = request.getRequestURI().toString();
		
		String token = uri.substring(uri.lastIndexOf("/") + 1);
		if(userService.authenticated(token)) {
			return true;
			
		}else {
			return false;
		}
	}
}
